package com.fand.manager.model.login;

import java.util.Date;
import java.util.Objects;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.date.DateUtil;
import com.fand.common.model.BaseDTO;
import com.fand.common.util.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Author: zhangjiabin
 * Email: javaboyok@163.com
 * CreateDate: 2021/6/27
 * Version: 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysUserLoginRecordSearchDTO extends BaseDTO {

    private String userName;
    private String userCode;

    private Date startDateTime;
    private Date endDateTime;

    private String start;
    private String end;

    public SysUserLoginRecordSearchDTO builder() {
        if (Objects.isNull(getSearchParams())) {
            return this;
        } else {
            SysUserLoginRecordSearchDTO sysUserLoginRecordSearchDTO = JsonUtils.jsonToPojo(JsonUtils.objectToJson(JsonUtils.jsonToPojo(getSearchParams(), SysUserLoginRecordSearchDTO.class)), SysUserLoginRecordSearchDTO.class);
            CopyOptions copyOptions = CopyOptions.create();
            copyOptions.setIgnoreNullValue(true);

            sysUserLoginRecordSearchDTO.setStartDateTime(DateUtil.parse(sysUserLoginRecordSearchDTO.getStart()));
            sysUserLoginRecordSearchDTO.setEndDateTime(DateUtil.parse(sysUserLoginRecordSearchDTO.getEnd()));

            BeanUtil.copyProperties(sysUserLoginRecordSearchDTO, this, copyOptions);
            return this;
        }
    }
}
